import pyautogui
import time


def autorun():

    n=0 
    pyautogui.PAUSE = 1   
    
    try:
        btn2=pyautogui.locateOnScreen('gpic/machis.png')
        print(pyautogui.center(btn2))
        pyautogui.moveTo(pyautogui.center(btn2),duration=1)
        pyautogui.click(pyautogui.center(btn2))
        time.sleep(0.5)
    except:
        pass
    time.sleep(0.5)

    try:
        btn3=pyautogui.locateOnScreen('gpic/vs5.png')
        print(pyautogui.center(btn3))
        pyautogui.moveTo(pyautogui.center(btn3),duration=1)
        pyautogui.click(pyautogui.center(btn3))
        pyautogui.moveTo(600,500,duration=1)
        time.sleep(0.5)
    except:
        pass
    time.sleep(0.5)

    try:
        btn4=pyautogui.locateOnScreen('gpic/jiandan.png')
        print(pyautogui.center(btn3))
        pyautogui.moveTo(pyautogui.center(btn4),duration=1)
        pyautogui.click(pyautogui.center(btn4))
        print('简单')
        time.sleep(0.5)
    except:
        pass
    time.sleep(0.5)

    try:
        btn5=pyautogui.locateOnScreen('gpic/pipei.png')
        print(pyautogui.center(btn5))
        pyautogui.moveTo(pyautogui.center(btn5),duration=1)
        pyautogui.click(pyautogui.center(btn5))
        print('匹配')
        time.sleep(0.5)
    except:
        pass

    while True:
        try:
            btn6=pyautogui.locateOnScreen('gpic/jin.png')
            print(pyautogui.center(btn6))
            pyautogui.moveTo(pyautogui.center(btn6),duration=1)
            pyautogui.click(pyautogui.center(btn6))
            print('确定进入')
            time.sleep(0.5)
            if btn6:
                break
        except:
            pass

    while True:
        try:
            btn6m=pyautogui.locateOnScreen('gpic/jin.png')
            if btn6m:
                print(pyautogui.center(btn6m))
                pyautogui.moveTo(pyautogui.center(btn6m),duration=1)
                pyautogui.click(pyautogui.center(btn6m))
        except:
            pass
        try:
            btn7=pyautogui.locateOnScreen('gpic/yase.png')
            print(pyautogui.center(btn7))
            pyautogui.moveTo(pyautogui.center(btn7),duration=1)
            pyautogui.click(pyautogui.center(btn7))
            print('选阿瑟')
            time.sleep(0.5)
            if btn7:
                break
        except:
            pass

    try:
        btn8=pyautogui.locateOnScreen('gpic/queding.png')
        print(pyautogui.center(btn8))
        pyautogui.moveTo(pyautogui.center(btn8),duration=1)
        pyautogui.click(pyautogui.center(btn8))
        print('确定')
        time.sleep(0.5)
        pyautogui.moveTo(600,400,duration=1)
    except:
        pass


    while True:
        try:

            time.sleep(70)
            

            print('进图')
            break
        except:
            pass

    time.sleep(25) ##进图移动了
    while True:
        pyautogui.keyDown('w')
        print('移动')
        time.sleep(18)
        pyautogui.press('2')
        time.sleep(0.5)
        pyautogui.press('3')
        pyautogui.keyUp('w')
        btno=pyautogui.locateOnScreen('gpic/jixu.png')
        time.sleep(1)
        pyautogui.click()
        if btno:
            print('胜利')
            break
        while True:
            time.sleep(0.5)
            pyautogui.press('k')
##            print('平a')
           
            n=n+1
            if n==20:
                pyautogui.press('i')
                pyautogui.keyDown('d')
                time.sleep(0.5)
                pyautogui.press('o')
                time.sleep(2)
                pyautogui.keyUp('d')
                time.sleep(3)
                n=0
                break
                

##            try:
##                btn11=pyautogui.locateOnScreen('gpic/vitory.png')
##                pyautogui.click()
##                if btn11:
##                    break
##            except:
##                pass
##            
    while True:
        try:
            btn12=pyautogui.locateOnScreen('gpic/jixu.png')
            pyautogui.moveTo(pyautogui.center(btn12),duration=1)
            pyautogui.click(pyautogui.center(btn12))
            print('继续')
            time.sleep(0.5)
            pyautogui.moveTo(600,400,duration=0.5)
        except:
            pass
        
        if btn12:
            break
        
    time.sleep(1)
    while True:
        try:
            time.sleep(0.5)
            pyautogui.click()
            btn13=pyautogui.locateOnScreen('gpic/jixu1.png')
            pyautogui.moveTo(pyautogui.center(btn13),duration=1)
            pyautogui.click(pyautogui.center(btn13))
            print('继续')
            time.sleep(0.5)
            pyautogui.moveTo(600,400,duration=1)
        except:
            pass
        if btn13:
            break
        
    while True:    
        try:
            btn14=pyautogui.locateOnScreen('gpic/zailai.png')
            pyautogui.moveTo(pyautogui.center(btn14),duration=1)
            pyautogui.click(pyautogui.center(btn14))
            print('再来')
            time.sleep(0.5)
        except:
            pass
        if btn14:
            break
        
    time.sleep(1)
    autorun()

            
           

##    t1=threading.Timer(2,autorun)
##    t1.start()
##    
if __name__=='__main__':
    autorun()



